{\rtf1\mac\ansicpg10000\cocoartf102
{\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fnil\fcharset77 Monaco;\f2\fswiss\fcharset77 Helvetica;
}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;\red191\green0\blue0;\red0\green0\blue191;
\red96\green96\blue96;\red0\green115\blue0;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f0\b\fs36 \cf2 LoopBuf		sample looping oscillator\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f1\b0\fs18 \cf2 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f2\fs24 \cf2 Plays and loops between two frames of a sample resident in memory.\
\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f0\b \cf2 LoopBuf.ar(numChannels,bufnum,rate,gate,startPos,loop,startLoop,endLoop,interpolation)\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f2\b0 \cf2 \
	
\f0\b numChannels
\f2\b0  - number of channels that the buffer will be.\
			this must be a fixed integer. The architecture of the SynthDef\
			cannot change after it is compiled.\
			warning: if you supply a bufnum of a buffer that has a different\
			numChannels then you have specified to the LoopBuf, it will\
			fail silently.\
	
\f0\b bufnum
\f2\b0  - the index of the buffer to use\
	
\f0\b rate
\f2\b0    - 1.0 is normal, 2.0 is one octave up, 0.5 is one octave down\
			-1.0 is backwards normal rate ... etc.\
	
\f0\b gate
\f2\b0  	positive gate starts playback from startPos\
			negative gate plays rest of sample from current position\
	
\f0\b startPos
\f2\b0  - sample frame to start playback\
	
\f0\b startLoop
\f2\b0  - sample frame of start of loop\
	
\f0\b endLoop
\f2\b0  - sample frame of end of loop\
	
\f0\b interpolation
\f2\b0  - 1 means no interpolation, 2 is linear, 4 is cubic interpolation\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f1\fs18 \cf2 \
\
\cf3 // Create buffer and SynthDef\cf2 \
(\
\cf3 // read a whole sound into memory\cf2 \
s = \cf4 Server\cf2 .internal;\
b = \cf4 Buffer\cf2 .read(s,\cf5 "sounds/a11wlk01.wav"\cf2 );\
\
\cf3 // make a simple sampler instrument\cf2 \
\cf4 SynthDef\cf2 (\cf5 "help-LoopBuf"\cf2 ,\{ \
	\cf4 arg\cf2  out=0, bufnum=0, rate=1, glide=0, gate=1, loopRel=0, startPos=0, startLoop, endLoop, ipol=2;\
	\cf4 var\cf2  env, signal;\
	rate = \cf4 Lag\cf2 .kr(rate, glide);\
	env = \cf4 EnvGen\cf2 .ar(\cf4 Env\cf2 .adsr(0.1,0.2,1,2), gate, doneAction: 2);\
	signal = \cf4 LoopBuf\cf2 .ar(1,bufnum, \cf4 BufRateScale\cf2 .kr(bufnum) * rate, gate+loopRel, startPos, startLoop, endLoop, ipol);\
	\cf4 Out\cf2 .ar(out, (signal * env).dup);\
\}).send(s);\
)\
\
\cf3 // start playback\cf2 \
s.sendMsg(\cf5 "/s_new"\cf2 , \cf5 "help-LoopBuf"\cf2 , 3000, 1, 0, \cf6 \\bufnum\cf2 , b.bufnum, \cf6 \\startLoop\cf2 , 5000, \cf6 \\endLoop\cf2 , 15000);\
\
s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\rate\cf2 , -1);	\cf3 // backwards\cf2 \
s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\rate\cf2 , 1);	\cf3 // forwards\cf2 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f2\fs24 \cf2 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f1\fs18 \cf2 s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\startLoop\cf2 , 11000, \cf6 \\endLoop\cf2 , 13000) \cf3 // change loop points
\f2\fs24 \cf2 \
\

\f1\fs18 s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\glide\cf2 , 5) \cf3 // 5 second glide
\f2\fs24 \cf2 \

\f1\fs18 s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\rate\cf2 , 2); \cf3 // up an octave\cf2 \
s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\rate\cf2 , -1); \cf3 // backwards again
\f2\fs24 \cf2 \

\f1\fs18 s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\rate\cf2 , 1);	\cf3 // back to normal
\f2\fs24 \cf2 \
\

\f1\fs18 s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\ipol\cf2 , 1);	\cf3 // no interpolation\cf2 \
s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\ipol\cf2 , 2);	\cf3 // linear interpolation\cf2 \
s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\ipol\cf2 , 4);	\cf3 // cubic interpolation
\f2\fs24 \cf2 \
\

\f1\fs18 \cf3 // release gate to hear post-loop\cf2 \
s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\gate\cf2 , 0);\
\
\cf3 // release instrument without post-loop\cf2 \
s.sendMsg(\cf5 "/s_new"\cf2 , \cf5 "help-LoopBuf"\cf2 , 3000, 1, 0, \cf6 \\bufnum\cf2 , b.bufnum, \cf6 \\startLoop\cf2 , 11000, \cf6 \\endLoop\cf2 , 13000);\
s.sendMsg(\cf5 "/n_set"\cf2 , 3000, \cf6 \\loopRel\cf2 , 1, \cf6 \\gate\cf2 , 0);\
\
}